package com.ccp.dev.qbdms.service.myScript;

import com.ccp.dev.core.basic.engine.IScript;
import com.ccp.dev.qbdms.model.WQbdDailyInspect;
import com.ccp.dev.qbdms.model.WQbdFalProblemreset;
import com.ccp.dev.qbdms.model.WQbdFalProblemPlan;
import com.ccp.dev.qbdms.model.WQbdProblemHandle;
import com.ccp.dev.qbdms.model.WQbdQualityTarget;
import com.ccp.dev.qbdms.model.WQbdQualityRevSu;
import com.ccp.dev.qbdms.model.WQbdQualityReview;
import com.ccp.dev.qbdms.model.WQbdQualitymanageSu;
import com.ccp.dev.qbdms.service.WQbdDailyInspectService;
import com.ccp.dev.qbdms.service.WQbdFalProblemPlanService;
import com.ccp.dev.qbdms.service.WQbdFalProblemresetService;
import com.ccp.dev.qbdms.service.WQbdProblemHandleService;
import com.ccp.dev.qbdms.service.WQbdQualityTargetService;
import com.ccp.dev.qbdms.service.WQbdQualityRevSuService;
import com.ccp.dev.qbdms.service.WQbdQualityReviewService;
import com.ccp.dev.qbdms.service.WQbdQualitymanageSuService;
import java.util.List;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.HashSet;
import java.util.Set;

/**
 * @author Cong
 */
@Component
public class MyScriptImpl implements IScript {

    @Resource
    private WQbdFalProblemresetService wQbdFalProblemresetService;
    @Resource
    private WQbdFalProblemPlanService wQbdFalProblemPlanService;
    @Resource
    private WQbdDailyInspectService wQbdDailyInspectService;
    @Resource
    private WQbdQualitymanageSuService wQbdQualitymanageSuService;
    @Resource
    private WQbdProblemHandleService wQbdProblemHandleService;
    @Resource
    private WQbdQualityTargetService wQbdQualityTargetService;
    @Resource
    private WQbdQualityRevSuService wQbdQualityRevSuService;
    @Resource
    private WQbdQualityReviewService wQbdQualityReviewService;

    public String getWQbdFalProblemresetDeptId(String businessid) {
        WQbdFalProblemreset wQbdFalProblemreset = wQbdFalProblemresetService.getOneById(businessid);
        return wQbdFalProblemreset.getfDutydeptRoom();
    }

    public Set getWQbdFalProblemPlanUserId(String businessid) {
        Set hs = new HashSet();
        WQbdFalProblemPlan wQbdFalProblemPlan = wQbdFalProblemPlanService.getByTrueId(businessid);
        hs.add(wQbdFalProblemPlan.getUserId());
        return hs;
    }

    public String getWQbdDailyInspectDeptId(String businessid) {
        WQbdDailyInspect wQbdDailyInspect = wQbdDailyInspectService.getOneById(businessid);
        return wQbdDailyInspect.getDutydept();
    }

    public boolean branchWQbdQualitymanage(String businessid,int num) {
        List<WQbdQualitymanageSu> wQbdQualityRewardsMsgSubList = wQbdQualitymanageSuService.getResponsibleunitByRefId(businessid);
        for(WQbdQualitymanageSu wQbdQualitymanageSu:wQbdQualityRewardsMsgSubList){
            wQbdQualitymanageSu.getResponsibleunit();
        }
        int listSize = wQbdQualityRewardsMsgSubList.size();
        return listSize>=num;
    }

    public String getWQbdQualitymanageSuDeptId(String businessid,int num) {
        List<WQbdQualitymanageSu> wQbdQualityRewardsMsgSubList = wQbdQualitymanageSuService.getResponsibleunitByRefId(businessid);
        return wQbdQualityRewardsMsgSubList.get(num-1).getResponsibleunit();
    }

    public boolean branchWQbdProblemHandle(String businessid,int num) {
        WQbdProblemHandle wQbdProblemHandle = wQbdProblemHandleService.getOneById(businessid);
        String changesuggest=wQbdProblemHandle.getChangesuggest();
        boolean branch;
        if(num==1){
            branch=changesuggest.equals("不更改");
        }else {
            branch=changesuggest.equals("批次性更改")||changesuggest.equals("永久性更改");
        }
        return branch;
    }

    public String getWQbdProblemHandleDeptId(String businessid) {
         WQbdProblemHandle wQbdProblemHandle = wQbdProblemHandleService.getOneById(businessid);
        return wQbdProblemHandle.getDutydeptid();
    }

    public String getWQbdQualityTargetDeptId(String businessid) {
        WQbdQualityTarget wQbdQualityTarget = wQbdQualityTargetService.getOneById(businessid);
        return wQbdQualityTarget.getDept();
    }

    public Set getWQbdProblemHandleDutypersonid(String businessid) {
        Set hs = new HashSet();
        WQbdProblemHandle wQbdProblemHandle = wQbdProblemHandleService.getOneById(businessid);
        hs.add(wQbdProblemHandle.getDutypersonid());
        return hs;
    }

    public boolean distributeWQbdQualityRevSu(String businessid,int num) {
        List<WQbdQualityRevSu> wQbdQualityRevSusList = wQbdQualityRevSuService.getQualityRevByRefId(businessid);
        int listSize = wQbdQualityRevSusList.size();
        return listSize>=num;
    }

    public Set getWQbdQualityRevSuPersionuserId(String businessid,int num) {
        Set hs = new HashSet();
        List<WQbdQualityRevSu> wQbdQualityRevSusList = wQbdQualityRevSuService.getQualityRevByRefId(businessid);
        hs.add(wQbdQualityRevSusList.get(num-1).getPersionuserId());
        return hs;
    }

    public String getWQbdQualityRevSuPersionuserIdStr(String businessid,int num) {
        List<WQbdQualityRevSu> wQbdQualityRevSusList = wQbdQualityRevSuService.getQualityRevByRefId(businessid);
        return wQbdQualityRevSusList.get(num-1).getPersionuserId();
    }

    public boolean branchWQbdQualityReview(String businessid,int num) {
        WQbdQualityReview wQbdQualityReview = wQbdQualityReviewService.getOneById(businessid);
        String changesuggest = wQbdQualityReview.getReviewcategory();
        boolean branch;
        if (num == 1) {
            branch = changesuggest.equals("技术");
        } else {
            branch = changesuggest.equals("管理");
        }
        return branch;
    }
}
